package org.restql.webapp;

import java.util.List;

import org.restql.db.resource.DatabaseResource;

public class RestQLResourceContainer {

	private List<DatabaseResource> resources;

	public void setResources(List<DatabaseResource> resources) {
		this.resources = resources;
	}

	public List<DatabaseResource> getResources() {
		return this.resources;
	}

	public DatabaseResource selectMatchingResource(String dbName, String tableName)
		throws RestQLException {

		DatabaseResource match = null;
		for (DatabaseResource res : resources) {
			if ( (res.getDbName().equals(dbName) &&
					res.getResourceName().equals(tableName)) ||
				  (res.getDbName().equals("*") &&
				  res.getResourceName().equals("*"))) {
				match = res;
			}
		}

		if (match == null) throw new RestQLException("No matching resource.");

		return match;
	}

}
